package com.shopoo.oauth.wap;

import javax.annotation.Resource;

import com.google.gson.Gson;
import com.shopoo.dto.MultiResponse;
import com.shopoo.dto.Response;
import com.shopoo.oauth.api.MenuService;
import com.shopoo.oauth.dto.clientobject.MenuCO;
import com.shopoo.oauth.dto.clientobject.MenuTreeDTO;
import com.shopoo.oauth.dto.cqe.MenuAddCmd;
import com.shopoo.oauth.dto.cqe.MenuQuery;
import com.shopoo.oauth.dto.cqe.MenuUpdateCmd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 菜单服务API
 * @Date 2020/10/29 4:07 下午
 * @Author <a href="mailto:android_li@sina.cn">Joe</a>
 **/
@Api(tags = "菜单服务API")
@RestController
@RequestMapping("/menus")
@Slf4j
public class MenuController {

    @Resource
    private MenuService menuService;

    /**
     * @Description 新增一个菜单信息
     *
     * @Param [oauthMenu]
     * @Return com.suntak.exception.model.Response
     * @Date 9:01 下午 2020/11/30
     * @Author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @ApiOperation("新增一个菜单信息")
    @PostMapping
    public Response save(@Validated @RequestBody MenuAddCmd menuAddCmd) {
        log.info("新增一个菜单信息：{}", new Gson().toJson(menuAddCmd));
        return menuService.save(menuAddCmd);
    }

    /**
     * @Description: 删除指定菜单的信息
     * @Author: limy66
     * @Date:   2021/3/23 17:33
     * @Param:  [menuId]
     * @Return: com.bngrp.common.entity.Response
     */
    @ApiOperation("删除指定菜单的信息")
    @DeleteMapping
    public Response deleteByMenuId(@RequestParam("menuId") Long menuId) {
        return menuService.deleteByMenuId(menuId);
    }

    @ApiOperation("更新指定菜单的信息")
    @PutMapping("/update")
    public Response update(@Validated @RequestBody MenuUpdateCmd menuUpdateCmd) {
        return menuService.update(menuUpdateCmd);
    }

    /**
     * @Description 查找所有的菜单
     *
     * @Param [oauthMenu]
     * @Return com.suntak.exception.model.Response
     * @Date 4:40 下午 2020/12/1
     * @Author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @ApiOperation("查找所有的菜单")
    @GetMapping("/list")
    public MultiResponse<MenuTreeDTO> findByConditions(@Validated MenuQuery menuQuery) {
        return menuService.findByConditions(menuQuery);
    }

    /**
     * @Description 根据用户ID查找菜单信息
     *
     * @Param [userId]
     * @Return com.suntak.exception.model.Response
     * @Date 10:23 上午 2020/10/30
     * @Author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @ApiOperation("根据用户ID查找菜单信息")
    @GetMapping("/nav")
    public MultiResponse<MenuCO> findMenusByUserId(@RequestHeader("userId") String userId) {
        return menuService.findMenusByUserId(userId);
    }
}
